//
//  BottomTextFieldView.m
//  HoldingBarrage
//
//  Created by lingji001 on 2018/8/21.
//  Copyright © 2018年 lingji001. All rights reserved.
//

#import "BottomTextFieldView.h"

@interface BottomTextFieldView ()<UITextFieldDelegate>

/**
 输入框
 */
@property (nonatomic, strong) UITextField *textField;

/**
 小型背景图
 */
@property (nonatomic, strong) UIView *smallView;


@end


@implementation BottomTextFieldView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        [self configUI];
        self.backgroundColor = [UIColor blackColor];
    }
    return self;
}

#pragma mark 初始化UI控件
- (void)initUI{
    self.smallView = [UIView new];
    [self addSubview:self.smallView];
    
    self.textField = [UITextField new];
    [self.smallView addSubview:self.textField];
    
    self.setttingButton = [UIButton new];
    [self addSubview:self.setttingButton];
    
    
    self.smallView.backgroundColor = [UIColor whiteColor];
    self.smallView.layer.cornerRadius = 20;
    
    self.textField.placeholder = @"请输入弹幕文字";
    self.textField.textAlignment = NSTextAlignmentCenter;
    self.textField.delegate = self;
    
    [self.setttingButton setTitle:@"设置" forState:UIControlStateNormal];
}

#pragma mark 为UI控件添加约束
- (void)configUI{
    [self.smallView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(15);
        make.right.mas_offset(-60);
        make.height.mas_offset(40);
        make.centerY.mas_offset(0);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_offset(0);
    }];
    
    [self.setttingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_offset(30);
        make.right.mas_offset(-15);
        make.centerY.equalTo(self.smallView);
    }];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (self.block) {
        self.block(textField.text);
    }
    [textField resignFirstResponder];
    textField.text = @"";
    return YES;
}

@end
